package org.teremail.mailbox;

import java.util.List;

import org.teremail.mailbox.Folder.SortKey;

/**
 * Data Access interface for the mailbox.  Will have some cross over with
 * the MessageDAO.
 * 
 * @author mike
 *
 */
public interface MailboxDAO {

    /**
     * Create a mailbox for the specified user name.
     * 
     * @param user
     * @return
     * @throws MailboxExistsException
     */
    MailboxDO create(String user) throws MailboxExistsException;

    /**
     * Find a folder for the specified mailbox and path.
     * 
     * @param mailbox
     * @param path
     * @return
     * @throws MailboxNotExistsException
     * @throws FolderNotExistsException
     */
    FolderDO findFolder(MailboxDO mailbox, Path path) 
            throws MailboxNotExistsException, FolderNotExistsException;

    /**
     * Save a folder data object.
     * 
     * @param inbox
     * @return
     * @throws FolderExistsException
     */
    FolderDO save(FolderDO inbox) throws FolderExistsException;

    void remove(MailboxDO mailbox, Path path) throws MailboxNotExistsException, 
            FolderNotExistsException;

    MailboxDO findMailbox(String user) throws MailboxNotExistsException;

    void renameFolder(MailboxDO mailbox, Path fromPath, Path toPath) 
            throws MailboxNotExistsException, FolderExistsException, FolderNotExistsException;

    void addMessage(FolderDO fdo, String messageId) throws FolderNotExistsException;

    List<FolderDO> getFolders(MailboxDO mailbox, Path root);

    List<EntryDO> getEntries(FolderDO f);
    
    List<EntryDO> getEntries(FolderDO fdo, int pageNo, int pageSize, SortKey...keys);

    EntryDO getEntry(FolderDO folder, int uid) throws EntryNotExistsException;

}
